//package editor.cn;
////Given a binary tree, determine if it is height-balanced.
////
//// For this problem, a height-balanced binary tree is defined as:
////
////
//// a binary tree in which the left and right subtrees of every node differ in he
////ight by no more than 1.
////
////
////
////
//// Example 1:
////
//// Given the following tree [3,9,20,null,null,15,7]:
////
////
////    3
////   / \
////  9  20
////    /  \
////   15   7
////
//// Return true.
////
////Example 2:
////
//// Given the following tree [1,2,2,3,3,null,null,4,4]:
////
////
////       1
////      / \
////     2   2
////    / \
////   3   3
////  / \
//// 4   4
////
////
//// Return false.
//// Related Topics 树 深度优先搜索
//// 👍 488 👎 0
//
//
////leetcode submit region begin(Prohibit modification and deletion)
///**
// * Definition for a binary tree node.
// * public class TreeNode {
// *     int val;
// *     TreeNode left;
// *     TreeNode right;
// *     TreeNode(int x) { val = x; }
// * }
// */
//class Solution {
//    public boolean isBalanced(TreeNode root) {
//
////        if (root == null) {
////            return true;
////        } else {
////            return Math.abs(height(root.left) - height(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right);
////        }
////    }
////
////    public int height(TreeNode root) {
////        if (root == null) {
////            return 0;
////        } else {
////            return Math.max(height(root.left), height(root.right)) + 1;
////        }
//
//
//        return height(root) >= 0;
//    }
//
//    public int height(TreeNode root) {
//        if (root == null) {
//            return 0;
//        }
//        int leftHeight = height(root.left);
//        int rightHeight = height(root.right);
//        if (leftHeight == -1 || rightHeight == -1 || Math.abs(leftHeight - rightHeight) > 1) {
//            return -1;
//        } else {
//            return Math.max(leftHeight, rightHeight) + 1;
//        }
//
//    }
//}
////leetcode submit region end(Prohibit modification and deletion)
